class Request {
	constructor(){}
	
	/**
	 * 上传
	 * @param {Object} uri
	 * @param {Object} files
	 */
	upload(uri,filePath,formData){
		return new Promise((succ,error)=>{
			let header = {
				Authorization: uni.getStorageSync("token"),
				'Request-Source': "APP"
			}
			uni.uploadFile({
				url: uri,
				filePath,
				name: "file",
				formData,
				header,
				success: (res)=>{
					succ(JSON.parse(res.data));
				},fail: (err)=>{
					error(err);
				}
			});
		})
	}


	
	/**
	 * post请求
	 * @param {Object} uri
	 * @param {Object} data
	 */
	post(uri,data){
		return this.request("POST",uri,{
			'content-type': 'application/json'
		},data);
	}
	
	/**
	 * @param {Object} uri
	 * @param {Object} data
	 */
	put(uri,data){
		return this.request("PUT",uri,{
			'content-type': 'application/json'
		},data);
	}
	
	/**
	 * @param {Object} uri
	 * @param {Object} data
	 */
	get(uri,data){
		return this.request("GET",uri,{},data);
	}
	
	/**
	 * @param {Object} uri
	 * @param {Object} data
	 */
	del(uri,data){
		return this.request("DELETE",uri,{'Content-Type': 'application/x-www-form-urlencoded'},data);
	}
	
	/**
	 * @param {Object} method
	 * @param {Object} uri
	 * @param {Object} header
	 * @param {Object} data
	 */
	request(method,uri,header,data){
		return new Promise((succ,error)=>{
			uni.request({
				url: uri,
				method,
				header,
				data,
				success: (res)=>{
					succ(res.data);
				},fail: (err)=>{
					error(err);
				}
			})
		})
	}
}
export default Request;